package org.s3.project.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.s3.project.entity.Merchant;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author cfx
 * @version 1.0
 * @Description
 * @date 2025/2/9 9:42
 */
@Mapper
@Repository
public interface MerchantMapper extends BaseMapper<Merchant> {
    //查询所有商家
    @Select("select * from merchant \n" +
            "where status=1 and  opening_status=1")
    List<Merchant> selectMerchants();

    //商家登录
    @Select("select * from merchant where contact_phone = #{name} and password = #{password}  ")
    Merchant login(@Param("name") String contact_phone,@Param("password") String password);

    // 查商家是否被冻结
    @Select("select * from merchant where  Status=0 and id=#{id} ")
    Merchant ShowStatus(@Param("id") long id);

    //登录的时候查询一下他是否申请过 ,为申请过就跳转申请页面
    @Select("select *from  merchant where opening_status=3  and id=#{id} ")
    Merchant  ShowoPening_status(@Param("id") long id);

    /**
     * 模糊查询商家
     * @param name 商家名称
     * @param create_time 创建时间
     * @param create_timeOne 创建时间
     * @return 商家列表
     */
    List<Merchant> selectMerchantCheckLike(@Param("name") String name,  @Param("create_time")String create_time, @Param("create_timeOne")String create_timeOne);

    /**
     * 更新商家状态
     * @param id 商家id
     * @param status 商家状态
     * @return 更新结果
     */
    @Update("update merchant set status = #{status} where id = #{id}")
    int updateMerchantStatus(@Param("id") int id, @Param("status")int status);

    /**
     * 批量更新商家状态
     * @param ids 商家id数组
     * @param status 商家状态
     * @return 更新结果
     */
    int updateMerchantStatusIds(@Param("ids") int[] ids, @Param("status")int status);

    //查询商家商品数量
    int selectMerchantProductCount(@Param("merchant_id") int merchant_id);

    //查询商家本月销售额
    int selectMerchantMonthSales(@Param("merchant_id") int merchant_id);
}
